package com.cgx.tablet.beeper.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.view.View;

import com.cgx.tablet.beeper.adapter.WinTransAdapter;
import com.cgx.tablet.beeper.bean.WinTransBean;
import com.cgx.tablet.beeper.databinding.ItemWinTransBinding;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

import java.util.List;


/**
 * CommunityResident
 * Created by Droven on 2017/12/23.
 */

public class WinTransViewHolder extends RecycleViewHolder<WinTransBean> implements View.OnClickListener {

    private ItemWinTransBinding mBinding;
    private WinTransAdapter.OnItemClickListener onItemClickListener;
    private List<WinTransBean> winTransBeans;

    public WinTransViewHolder(View itemView, WinTransAdapter.OnItemClickListener onItemClickListener, List<WinTransBean> winTransBeans) {
        super(itemView);
        mBinding = DataBindingUtil.bind(itemView);
        ScreenAdapterTools.getInstance().loadView(itemView);
        mBinding.windowRl.setOnClickListener(this);
        this.winTransBeans = winTransBeans;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public void Bind(@NonNull WinTransBean winTransBean) {
        mBinding.windowName.setText(winTransBean.getWinName());
        mBinding.windowCb.setChecked(winTransBean.isChecked());
    }

    @Override
    public void onClick(View view) {
        // 每次点击时，先将所有的selected设为false，并且将当前点击的item 设为true， 刷新整个视图
        if (onItemClickListener != null)
            onItemClickListener.onItemClick(view, getAdapterPosition(), winTransBeans);
    }
}
